package cn.tedu.course.role.controller;

import cn.tedu.course.base.response.JsonResult;
import cn.tedu.course.role.mapper.RoleMapper;
import cn.tedu.course.role.pojo.dto.RoleQuery;
import cn.tedu.course.role.pojo.dto.RoleSaveParam;
import cn.tedu.course.role.pojo.vo.RoleVO;
import cn.tedu.course.role.service.RoleService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.apache.tomcat.Jar;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/role/")
public class RoleController {
    @Autowired
    RoleService roleService;

    @Operation(summary = "查询列表")
    @ApiOperationSupport(order = 10)
    @GetMapping("select")
    public JsonResult selectRole(RoleQuery roleQuery){
        log.debug("查询角色列表: roleQuery={}", roleQuery);
        List<RoleVO> list = roleService.selectRole(roleQuery);
        return JsonResult.ok(list);
    }
    @Operation(summary = "保存角色")
    @ApiOperationSupport(order = 20)
    @PostMapping("save")
    public JsonResult saveRole(@Validated RoleSaveParam roleSaveParam){
        log.debug("保存角色:roleSaveParam={}",roleSaveParam);
        roleService.saveRole(roleSaveParam);
        return JsonResult.ok();
    }
    @Operation(summary = "删除角色")
    @ApiOperationSupport(order = 30)
    @PostMapping("delete/{id}")
    public JsonResult deleteRole(@PathVariable Long id){
        log.debug("删除角色:id={}",id);
        roleService.deleteRole(id);
        return JsonResult.ok();
    }

}
